package com.ruoyi.project.dzbqTask.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.project.dzbqTask.domain.DzbqTask;
import com.ruoyi.project.dzbqTask.service.IDzbqTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 电子标签任务Controller
 *
 * @author wz
 * @date 2023-01-06
 */
@Controller
@RequestMapping("/dzbq/dzbqTask")
public class DzbqTaskController extends BaseController
{
    private String prefix = "dzbq/dzbqTask";

    @Autowired
    private IDzbqTaskService dzbqTaskService;

    //@RequiresPermissions("dzbq:dzbqTask:view")
    @GetMapping()
    public String dzbqTask()
    {
        return prefix + "/dzbqTask";
    }

    /**
     * 查询电子标签任务列表
     */
    //@RequiresPermissions("dzbq:dzbqTask:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DzbqTask dzbqTask)
    {
        startPage();
        List<DzbqTask> list = dzbqTaskService.selectDzbqTaskList(dzbqTask);
        return getDataTable(list);
    }

    /**
     * 导出电子标签任务列表
     */
    //@RequiresPermissions("dzbq:dzbqTask:export")
    @Log(title = "电子标签任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DzbqTask dzbqTask)
    {
        List<DzbqTask> list = dzbqTaskService.selectDzbqTaskList(dzbqTask);
        ExcelUtil<DzbqTask> util = new ExcelUtil<DzbqTask>(DzbqTask.class);
        return util.exportExcel(list, "dzbqTask");
    }

    /**
     * 新增电子标签任务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存电子标签任务
     */
    //@RequiresPermissions("dzbq:dzbqTask:add")
    @Log(title = "电子标签任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DzbqTask dzbqTask)
    {
        return toAjax(dzbqTaskService.insertDzbqTask(dzbqTask));
    }

    /**
     * 修改电子标签任务
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        DzbqTask dzbqTask = dzbqTaskService.selectDzbqTaskById(id);
        mmap.put("dzbqTask", dzbqTask);
        return prefix + "/edit";
    }

    /**
     * 修改保存电子标签任务
     */
    //@RequiresPermissions("dzbq:dzbqTask:edit")
    @Log(title = "电子标签任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DzbqTask dzbqTask)
    {
        return toAjax(dzbqTaskService.updateDzbqTask(dzbqTask));
    }

    /**
     * 删除电子标签任务
     */
    //@RequiresPermissions("dzbq:dzbqTask:remove")
    @Log(title = "电子标签任务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dzbqTaskService.deleteDzbqTaskByIds(ids));
    }

    /**
     * 重新发送亮灯
     */
    @Log(title = "重新发送亮灯", businessType = BusinessType.UPDATE)
    @PostMapping("/reSend")
    @ResponseBody
    public AjaxResult updateStatus() {
        return toAjax(dzbqTaskService.reSend());
    }
}
